<template>
  <view style="padding: 40rpx; padding-top: 30rpx">
    <view class="order_box">

      <image v-show="indent == '处理厂司机'" style="width: 100%;" @click="submit" mode="widthFix"
        src="https://28-1325662301.cos.ap-shanghai.myqcloud.com/%E9%9D%92%E5%B2%9B%E5%B0%8F%E7%A8%8B%E5%BA%8F%2FGroup%202399.png" />
      <image v-show="indent == '养殖场账号'" style="width: 100%;" @click="appCard" mode="widthFix"
        src="https://28-1325662301.cos.ap-shanghai.myqcloud.com/%E9%9D%92%E5%B2%9B%E5%B0%8F%E7%A8%8B%E5%BA%8F%2FGroup%202400.png" />
      <image v-show="indent == '调度员'" style="width: 100%;" @click="taskTarget" mode="widthFix"
        src="https://28-1325662301.cos.ap-shanghai.myqcloud.com/%E9%9D%92%E5%B2%9B%E5%B0%8F%E7%A8%8B%E5%BA%8F%2FGroup%202395.png" />
      <image v-show="indent == '任务发布实验员'" style="width: 100%;" @click="taskTarget" mode="widthFix"
        src="https://28-1325662301.cos.ap-shanghai.myqcloud.com/%E9%9D%92%E5%B2%9B%E5%B0%8F%E7%A8%8B%E5%BA%8F%2FGroup%202395.png" />

    </view>
    <view v-if="indent != '调度员'" class="grid_box">
      <view @click="goQuest('进行中任务')" class="gd_img_num">
        <image style="width: 80rpx; height: 80rpx"
          src="https://28-1325662301.cos.ap-shanghai.myqcloud.com/%E9%9D%92%E5%B2%9B%E5%B0%8F%E7%A8%8B%E5%BA%8F%2FGroup%202390.png" />
        <view style="
              font-size: 36rpx;
              color: #000;
              font-weight: 700;
              margin-bottom: 10rpx;
            ">
          {{ indent == '处理厂司机' ? runningCar : indent == '养殖场账号' ? runningFarm : '' }}
        </view>
        <view style="font-size: 24rpx"> {{ indent == '养殖场账号' ? '进行中预约工单' : indent == '任务发布实验员' ? '我的进行中任务数' : '我的进行中工单数' }} </view>
      </view>
      <view style="width: 320rpx; display: flex; flex-direction: column">
        <view class="col_li" style="margin-bottom: 20rpx" @click="tartTranQuest">
          <image style="width: 80rpx; height: 80rpx"
            src="https://28-1325662301.cos.ap-shanghai.myqcloud.com/%E9%9D%92%E5%B2%9B%E5%B0%8F%E7%A8%8B%E5%BA%8F%2FGroup%202383.png" />
          <view style="margin-left: 20rpx">
            <view class="clo_li_num">{{ indent == '处理厂司机' ? receiveOrder : indent == '养殖场账号' ? noPay : '' }} </view>
            <view style="font-size: 24rpx">
              {{ indent == '处理厂司机' ? '待接单数量' : indent == '任务发布实验员' ? '我的累计完成' : '待缴费用' }}
            </view>
          </view>
        </view>
        <view @click="goQuest('历史记录')" class="col_li">
          <image style="width: 80rpx; height: 80rpx"
            src="https://28-1325662301.cos.ap-shanghai.myqcloud.com/%E9%9D%92%E5%B2%9B%E5%B0%8F%E7%A8%8B%E5%BA%8F%2FGroup%202380.png" />
          <view style="margin-left: 20rpx">
            <view class="clo_li_num"> {{ indent == '处理厂司机' ? dayNum : indent == '养殖场账号' ? waitFarm : '' }} </view>
            <view style="font-size: 24rpx;">
              {{ indent == '处理厂司机' ? '今日已处理数' : indent == '养殖场账号' ? '待完成预约' : indent == '任务发布实验员' ? '我的待接单' : '' }}
            </view>
          </view>
        </view>
      </view>
      <view v-if="indent == '处理厂司机'" style="margin-top: 30rpx;width: 100%;">
        <view class="col_li" style="margin-bottom: 20rpx;width: 100%;">
          <image style="width: 80rpx; height: 80rpx"
            src="https://28-1325662301.cos.ap-shanghai.myqcloud.com/%E9%9D%92%E5%B2%9B%E5%B0%8F%E7%A8%8B%E5%BA%8F%2FGroup%202393.png" />
          <view style="margin-left: 30rpx" @click="carStop">
            <view class="clo_li_num"> 车辆异常上报 </view>
            <view style="font-size: 24rpx"> 车辆报停按钮，上传异常信息 </view>
          </view>
        </view>
      </view>

    </view>
    <view v-if="indent == '调度员'" class="grid_box">
      <view class="gd_img_num">
        <image style="width: 80rpx; height: 80rpx"
          src="https://28-1325662301.cos.ap-shanghai.myqcloud.com/%E9%9D%92%E5%B2%9B%E5%B0%8F%E7%A8%8B%E5%BA%8F%2FGroup%202389.png" />
        <view style="
              font-size: 36rpx;
              color: #000;
              font-weight: 700;
              margin-bottom: 10rpx;
            ">
          {{ running + leisure + fault }}
        </view>
        <view style="font-size: 24rpx"> 全部收运车辆 </view>
      </view>
      <view class="gd_img_num">
        <image style="width: 80rpx; height: 80rpx"
          src="https://28-1325662301.cos.ap-shanghai.myqcloud.com/%E9%9D%92%E5%B2%9B%E5%B0%8F%E7%A8%8B%E5%BA%8F%2FGroup%202390.png" />
        <view style="
              font-size: 36rpx;
              color: #000;
              font-weight: 700;
              margin-bottom: 10rpx;
            ">
          {{ running }}
        </view>
        <view style="font-size: 24rpx"> 收运中车辆数量 </view>
      </view>
      <view style="margin-top: 10px;" class="gd_img_num">
        <image style="width: 80rpx; height: 80rpx"
          src="https://28-1325662301.cos.ap-shanghai.myqcloud.com/%E9%9D%92%E5%B2%9B%E5%B0%8F%E7%A8%8B%E5%BA%8F%2FGroup%202383.png" />
        <view style="
              font-size: 36rpx;
              color: #000;
              font-weight: 700;
              margin-bottom: 10rpx;
            ">
          {{ fault }}
        </view>
        <view style="font-size: 24rpx"> 报停中车辆数量 </view>
      </view>
      <view style="margin-top: 10px;" class="gd_img_num">
        <image style="width: 80rpx; height: 80rpx"
          src="https://28-1325662301.cos.ap-shanghai.myqcloud.com/%E9%9D%92%E5%B2%9B%E5%B0%8F%E7%A8%8B%E5%BA%8F%2FGroup%202391.png" />
        <view style="
              font-size: 36rpx;
              color: #000;
              font-weight: 700;
              margin-bottom: 10rpx;
            ">
          {{ leisure }}
        </view>
        <view style="font-size: 24rpx"> 空闲中车辆数量 </view>
      </view>
      <view v-if="indent == '处理厂司机'" style="margin-top: 30rpx;width: 100%;">
        <view class="col_li" style="margin-bottom: 20rpx;width: 100%;">
          <image style="width: 80rpx; height: 80rpx"
            src="https://28-1325662301.cos.ap-shanghai.myqcloud.com/%E9%9D%92%E5%B2%9B%E5%B0%8F%E7%A8%8B%E5%BA%8F%2FGroup%202393.png" />
          <view style="margin-left: 30rpx" @click="carStop">
            <view class="clo_li_num"> 车辆异常上报 </view>
            <view style="font-size: 24rpx"> 车辆报停按钮，上传异常信息 </view>
          </view>
        </view>
      </view>

    </view>
    <view class="card_box" v-if="indent != '任务发布实验员'">
      <div style="height: 20px;"></div>
      <div style="font-size: 14px;margin-left: 5%">有机质收运量趋势图</div>
      <div style="height: 15rpx;"></div>
      <qiun-data-charts style="width: 100%;height: 400rpx;margin-top: 10px;" :canvas2d="true"
        canvasId="cSzLoQHbVGhyVGQoVMEiaJwNPHqLAyma" type="area" :opts="opts" :chartData="chartData" />
    </view>
    <view class="card_search_box" v-if="indent != '任务发布实验员'">
      <view>
        <picker @change="bindPickerChangeCars" :value="index" :range="week">
          <div class="chooseChart">
            <div>图表按照每{{ week[index] }}呈现</div>
          </div>
        </picker>
      </view>
      <view v-if="indent == '养殖场账号'">
        <picker @change="bindPickerChange" :value="index" :range="array">
          <input style="text-align: center;" placeholder="请选择有机质类型" disabled v-model="farmChart.type" type="text" />
        </picker>
      </view>
      <view v-if="indent == '调度员'">
        <picker @change="bindPickerDispatch" :value="index" :range="array">
          <input style="text-align: center;" placeholder="请选择有机质类型" disabled v-model="dispatch.organicType"
            type="text" />
        </picker>
      </view>
    </view>
    <!-- 待调整 -->
    <view class="order_box" style="margin-top: 40rpx;" v-if="indent == '任务发布实验员'">
      <image style="width: 100%;" @click="taskTarget" mode="widthFix"
        src="https://28-1325662301.cos.ap-shanghai.myqcloud.com/%E9%9D%92%E5%B2%9B%E5%B0%8F%E7%A8%8B%E5%BA%8F%2FGroup%202395.png" />
    </view>
    <view style="font-size: 36rpx; font-weight: 700; margin-top: 30rpx" v-if="indent != '任务发布实验员'">
      今日已收集有机质（吨）
    </view>
    <view style="font-size: 36rpx; font-weight: 700; margin-top: 30rpx" v-else>
      进行中任务看板
    </view>
    <view v-if="indent == '任务发布实验员'">
      <view class="system_li_box"  v-for="(i, index) in allType" :key="index" v-if="allType.length != 0">
      <view style="display: flex; align-items: center">
        <view class="li_box_point">
        </view>
        <view style="display: flex; flex-direction: column">
          <view style="
                font-size: 36rpx;
                font-weight: 700;
                margin-bottom: 10rpx;
                vertical-align: text-top;
              ">
            {{ i.name }}
          </view>
          <!-- 暂无数据对接 -->
          <view style="font-size: 28rpx"> 预计待收集： 0吨 </view>
        </view>
      </view>
      <view style="font-size: 32rpx; font-weight: 700; color: #54c68d">
        {{ i.value }}
      </view>
    </view>
    <view class="system_li_box" v-if="allType.length === 0 && indent == '任务发布实验员'" v-for="(i, index) in allType" :key="index">
      <view style="display: flex; align-items: center">
        <view class="li_box_point">
        </view>
        <view style="display: flex; flex-direction: column">
          <view style="
                font-size: 36rpx;
                font-weight: 700;
                margin-bottom: 10rpx;
                vertical-align: text-top;
              ">
            暂无
          </view>
          <!-- 暂无数据对接 -->
          <view style="font-size: 28rpx"> 预计待收集： 0吨 </view>
        </view>
      </view>
      <view style="font-size: 32rpx; font-weight: 700; color: #f3744d">
        {{ i.value }}
      </view>
    </view>
    </view>
    <view v-if="indent != '任务发布实验员'">
      <view class="li_box" v-if="allType.length != 0 && indent != '任务发布实验员'" v-for="(i, index) in allType" :key="index">
      <view style="display: flex; align-items: center">
        <view class="li_box_point">
        </view>
        <view style="display: flex; flex-direction: column">
          <view style="
                font-size: 36rpx;
                font-weight: 700;
                margin-bottom: 10rpx;
                vertical-align: text-top;
              ">
            {{ i.name }}
          </view>
          <!-- 暂无数据对接 -->
          <view style="font-size: 28rpx"> 预计待收集： 0吨 </view>
        </view>
      </view>
      <view style="font-size: 32rpx; font-weight: 700; color: #f3744d">
        {{ i.value }}
      </view>
    </view>
    <view class="li_box" v-if="allType.length === 0 && indent != '任务发布实验员'" v-for="(i, index) in allType" :key="index">
      <view style="display: flex; align-items: center">
        <view class="li_box_point">
        </view>
        <view style="display: flex; flex-direction: column">
          <view style="
                font-size: 36rpx;
                font-weight: 700;
                margin-bottom: 10rpx;
                vertical-align: text-top;
              ">
            暂无
          </view>
          <!-- 暂无数据对接 -->
          <view style="font-size: 28rpx"> 预计待收集： 0吨 </view>
        </view>
      </view>
      <view style="font-size: 32rpx; font-weight: 700; color: #f3744d">
        {{ i.value }}
      </view>
    </view>
    </view>
      
      
    
    <u-overlay :show="showModal" @click="showModal = false">
      <view class="warp">
        <view class="rect" @tap.stop>
          <div style="height: 4vh;"></div>
          <div class="km" v-if="kmValue == ''">刷新查看距离</div>
          <div class="km" v-if="kmValue != ''">当前距离收运点：{{ kmValue }}{{ kmUnit }}</div>
          <div style="height: 4vh;"></div>
          <div style="display: flex;justify-content:center;">
            <div class="refresh" @click="refresh">刷新</div>
          </div>
          <div style="height: 4vh;"></div>
          <div class="tip">*离收运点距离小于1000M时可以上报</div>
          <div style="height: 4vh;"></div>
        </view>
      </view>
    </u-overlay>
    <view class="li_box" style="justify-content: center;" v-if="allType.length === 0">
      暂无数据
    </view>
    <div style="height: 5vh;"></div>
  </view>
</template>
<script>
import {
  needMonney,
  taskList,
  dispatchOrganic,
  driverCount,
  getNearFarm,
  experCategory,
  experCurrent,
  experTotal,
  lastTime,
  farmBord,
  organicType,
  farmEcharts,
  days,
  collect,
  estimated,
  stats,
  task,
  dispatcherEcharts,
  workNum,
  ordNum, farmIndex, farmMonery, farmOrder
} from '../../common/example.js';
import qiunDataCharts from '@/pagesScreen/subpackageuni/qiun-data-charts/components/qiun-data-charts/qiun-data-charts.vue'
// import { allType } from '../../pagesFarmer/api/api.js';
export default {
  components: {
    qiunDataCharts
  },
  data() {
    return {
      dispatchMode: '',
      runningFarm: 0,
      waitFarm: 0,
      isPay: 0,
      noPay: 0,
      showModal: false,
      indent: '',
      expert: [
        {
          title: '已完成任务数', value: 0
        },
        {
          title: '未完成任务数', value: 0
        }
      ],
      lastFeedbackTime: '',//最新反馈时间
      test: {
        unstarted: 0,
        completed: 0
      },
      allType: [],
      base: '',
      array: [],
      index: 0,
      farmChart: {
        type: '',
        date: ''
      },
      yj: {
        text1: '',
        weight1: 0,
        text2: '',
        weight2: 0
      },
      driver: {
        type: 'week'
      },
      money: {
        a: 0,
        b: 0,
      },
      predicOrganicWeightVOList: [],//养殖场预计
      todayOrganicWeightVOList: [],//养殖场今日
      totalOrganicWeightVOList: [],//养殖场累计
      indexs: 0,
      state: false,
      receiveOrder: 0,//待接
      indexss: 0,//养殖场图表日期切换
      week: ['周', '月', '年'],
      alDay: '',//已加入天数
      nickName: '',//昵称
      driverdung: 0,//司机收集牛粪
      driversewage: 0,//司机收集污水
      dung: 0,//牛粪
      sewage: 0,//污水
      predictDung: 0,//预计收集牛粪
      predictSewage: 0,//预计收集污水
      leisure: 0,//空闲
      running: 0,//收运中
      fault: 0,//报停中
      pending: 0,//待接单
      aleardy: 0,//已完成
      worknums: 0,//接受工单次数
      dayNum: 0,//今日已接
      dNum: 0,//待接单
      userInfo: {},
      flag: true,
      role: '',//处理厂司机/养殖场账号
      chartData: {},
      currentPage: '',
      opts: {
        color: [
          "#18512c"
        ],
        padding: [15, 15, 0, 5],
        enableScroll: false,
        legend: {},
        xAxis: {
          disableGrid: true,
        },
        yAxis: {
          data: [
            {
              min: 0,
            },
          ],
        },
        extra: {
          column: {
            type: "group",
            width: 30,
            activeBgColor: "#000000",
            activeBgOpacity: 0.08,
          },
        },
      },
      lat: '',
      lon: '',
      kmValue: '',
      kmUnit: '',
      fillOrd: {},
      dispatch: {
        organicType: null,
        type: 'week'
      },
      indexDis: 0,
      runningCar: 0,//司机进行中任务
    };
  },
  methods: {
    goQuest(i) {
      if (this.indent == '处理厂司机') {
        uni.navigateTo({
          url: `/pagesDriver/system/quest?flag=${i}`
        })
      } else {
        uni.navigateTo({
          url: `/pagesCopy/index/Appointmentrecords`
        })
      }

    },
    falist() {
      farmOrder({}).then(res => {
        console.log(res.data, '预约记录');
        if (res.data.code == 200) {
          this.runningFarm = res.data.data.filter((item) => item.appointDetailState == 1).length;
          console.log(this.runningFarm, 'this.runningFarm');

          this.waitFarm = res.data.data.filter((item) => item.appointDetailState === 0).length;
        }
      })
    },
    tartTranQuest() {
      if (this.indent == '养殖场账号') {
        uni.navigateTo({
          url: `/pagesFarmer/index/fees`
        })
      } else {
        let flag = '待接单任务';
        uni.navigateTo({
          url: `/pagesDriver/system/quest?flag=${flag}`
        })
      }

    },
    bindPickerChange: function (e) {
      let t = this;
      console.log('picker发送选择改变，携带值为', e.detail.value)
      let index = e.detail.value;
      console.log(t.array[e.detail.value], 't.range[index]');
      t.farmChart.type = t.array[index];
      t.chartsFarm(this.farmChart.date);
    },
    bindPickerDispatch(e) {
      let t = this;
      console.log('picker发送选择改变，携带值为', e.detail.value)
      let value = e.detail.value;
      console.log(t.array[value], 't.range[t.index]');
      t.dispatch.organicType = t.array[value];
      this.chartsDiapatch(t.dispatch);
    },
    webs() {
      let url = 'https://pro.surveyking.cn/s/wkT0OO'
      uni.navigateTo({
        url: '/pagesDispatch/index/webview?url=' + url
      })
    },
    // 缴费
    fee() {
      uni.navigateTo({ url: '/pagesFarmer/index/fees' })
    },
    // 查看工单
    looks() {
      if (this.receiveOrder == 0) {
        uni.showToast({
          title: '当前暂无工单',
          icon: 'none',
          mask: true
        })
      } else {
        uni.navigateTo({ url: '/pagesDriver/system/workOrder' })
      }

    },
    //   提交
    submit() {
      let t = this;
      console.log(t.kmUnit, t.kmValue);
      if (t.kmValue < 1000 && t.kmUnit == 'm') {
        uni.navigateTo({ url: '/pagesDriver/system/filling' });
        console.log(this.fillOrd);

        uni.setStorageSync('fillWork', this.fillOrd)
      } else {
        t.showModal = true;
      }
      return;
    },
    refresh() {
      const getLocationAsync = () => {
        return new Promise((resolve, reject) => {
          uni.getLocation({
            type: 'gcj02',
            success: function (res) {
              resolve(res); // 将位置信息传递给resolve
            },
            fail: function (err) {
              reject(err); // 处理获取位置失败的情况
            }
          });
        });
      };
      (async () => {
        try {
          const location = await getLocationAsync(); // 等待获取位置信息
          console.log(location, 'location'); // 输出位置信息到控制台

          // 调用getNearFarm并传递位置信息
          const response = await getNearFarm({
            lat: location.latitude,
            lon: location.longitude
          });

          console.log(response.data, 'response'); // 输出getNearFarm的响应数据到控制台
          if (response.data.code == 200) {
            this.kmValue = response.data.data.distance;
            this.kmUnit = response.data.data.unit;
            this.fillOrd = response.data.data.workOrderDetail;
            this.fillOrd.farmName = response.data.data.farmName;
            this.fillOrd.licenseNumber = response.data.data.licenseNumber;
            uni.showToast({
              title: '已重新定位',
              icon: 'none'
            })
            if (this.kmValue < 1000 && this.kmUnit == 'm') {
              this.showModal = false;
            }
            console.log(this.kmValue);
            uni.setStorageSync('fillWork', this.fillOrd)
          } else {
            uni.showToast({
              title: response.data.msg,
              icon: 'none'
            })
          }
        } catch (error) {
          console.error('Error:', error); // 处理可能的错误
        }
      })();
    },

    // 管理
    manage() {
      uni.navigateTo({ url: '/pagesDispatch/index/quest' })
    },
    carStop() {
      uni.navigateTo({ url: '/pagesDriver/system/carStop' })
    },
    toggleIndex(i, index) {
      this.indexs = index;
      this.chartsWeek(i);
    },
    // 养殖场日期切换
    toggleIndexs(i, index) {
      this.indexss = index;
      this.chartsFarm(i);
    },
    //调度员图表日期切换
    toggleDispatch(i, index) {
      // this.indexDis = index; 
      console.log(i);

      if (i == 0) {
        this.dispatch.type = 'week';
        this.chartsDiapatch(this.dispatch);
      } else if (i == 1) {
        this.dispatch.type = 'month';
        this.chartsDiapatch(this.dispatch);
      } else {
        this.dispatch.type = 'year';
        this.chartsDiapatch(this.dispatch);
      }
    },
    //司机图表日期切换
    toggleIndexCar(i, index) {
      console.log(i, 'iii');

      // this.indexs = index;
      console.log(i, 'i');
      if (i == 0) {
        console.log('执行周');
        this.driver.type = 'week';
        this.chartsCar(this.driver.type);
      } else if (i == 1) {
        console.log('执行月');

        this.driver.type = 'month';
        this.chartsCar(this.driver.type);
      } else {
        console.log('执行年');
        this.driver.type = 'year';
        this.chartsCar(this.driver.type);
      }
    },
    chartsDiapatch(i) {
      dispatcherEcharts({
        type: i.type,
        organicType: i.organicType
      }).then(response => {
        console.log(response.data, '调度员图表');
        const week = response.data.data.map((item) => item.name)
        const value = response.data.data.map((item) => item.value);
        let res = {
          categories: week,
          series: [
            {
              name: '收运量(吨)',
              data: value
            }
          ]
        }
        this.chartData = JSON.parse(JSON.stringify(res));
      })

    },
    chartsFarm(i) {
      console.log(i, 'iiiiiii');

      if (i === 0) {
        this.farmChart.date = 7;
      } else if (i == 1) {
        this.farmChart.date = 30;
      } else if (i == 2) {
        this.farmChart.date = 365;
      }
      // 养殖场图表
      if (!i) {
        farmEcharts({
          organicType: this.farmChart.type,
          timeSort: 7,
        }).then(response => {
          console.log(response.data, '养殖场图表');
          const week = response.data.data.map((item) => item.timeNumber)
          const value = response.data.data.map((item) => item.totalValue);
          let res = {
            categories: week,
            series: [
              {
                name: '收运量(吨)',
                data: value
              }
            ]
          }
          this.chartData = JSON.parse(JSON.stringify(res));
        })
      } else if (i == '月') {
        farmEcharts({
          organicType: this.farmChart.type,
          timeSort: this.farmChart.date,
        }).then(response => {
          console.log(response.data, '养殖场图表');
          const week = response.data.data.map((item) => item.timeNumber)
          const value = response.data.data.map((item) => item.totalValue);
          let res = {
            categories: week,
            series: [
              {
                name: '收运量',
                data: value
              }
            ]
          }
          this.chartData = JSON.parse(JSON.stringify(res));
        })
      } else if (i == '年') {
        farmEcharts({
          organicType: this.farmChart.type,
          timeSort: this.farmChart.date,
        }).then(response => {
          console.log(response.data, '养殖场图表');
          const week = response.data.data.map((item) => item.timeNumber)
          const value = response.data.data.map((item) => item.totalValue);
          let res = {
            categories: week,
            series: [
              {
                name: '收运量',
                data: value
              }
            ]
          }
          this.chartData = JSON.parse(JSON.stringify(res));
        })
      } else {
        farmEcharts({
          organicType: this.farmChart.type,
          timeSort: 7,
        }).then(response => {
          console.log(response.data, '养殖场图表');
          const week = response.data.data.map((item) => item.timeNumber)
          const value = response.data.data.map((item) => item.totalValue);
          let res = {
            categories: week,
            series: [
              {
                name: '收运量',
                data: value
              }
            ]
          }
          this.chartData = JSON.parse(JSON.stringify(res));
        })
      }

    },
    bindPickerChangeCars: function (e) {
      console.log(this.indent);
      console.log(e.detail.value);
      if (this.indent == '处理厂司机') {
        this.toggleIndexCar(e.detail.value)
      } else if (this.indent == '调度员') {
        this.toggleDispatch(e.detail.value);
      } else {
        this.toggleIndexs(e.detail.value);
      }
      this.index = e.detail.value;
      return;


    },
    carStop() {
      uni.navigateTo({ url: '/pagesDriver/system/carStop' })
    },
    chartsCar(i) {
      console.log(i, '司机的i');
      driverCount(i).then(response => {
        console.log(response.data, '司机图表');
        const week = response.data.data.map((item) => item.name)
        const value = response.data.data.map((item) => item.value);
        let res = {
          categories: week,
          series: [
            {
              name: '收运量(吨)',
              data: value
            }
          ]
        }
        this.chartData = JSON.parse(JSON.stringify(res));
      })
    },
    //养殖场预约
    appCard() {
      uni.navigateTo({
        url: "/pagesCopy/index/Appointmentrecords"
      });
    },
    //任务管理
    taskTarget() {
      uni.navigateTo({
        url: "/pagesDispatch/index/tran"
      });
    }

  },
  mounted() {
    // taskList({ workOrderDetailState: '' }).then(res => {
    //     console.log(res.data, '列表');
    //     if (res.data.code == 200) {
    //       this.runningCar = res.data.data.filter((item) => item.workOrderState == 4).length;
    //       console.log(this.list, 'list1');
    //     }
    //   })
    this.falist();
    this.chartsCar('week');
    console.log(this.allType);
    this.kmUnit = '';
    this.kmValue = '';
    // driverCount({}).then(res=>{
    //   console.log(res,'res----------------');
    // })
    uni.hideHomeButton();
    this.indent = uni.getStorageSync('pageIndent');
    this.role = uni.getStorageSync('userInfo').remark;
    this.nickName = uni.getStorageSync('userInfo').nickName;
    farmBord({
      userType: this.role == '养殖场账号' ? 'farmer' : this.role == '处理厂司机' || this.role == '调度员司机' ? 'driver' : this.role == '调度员' ? 'dispatcher' : ''
    }).then(res => {
      // console.log(res.data,'有机质类型');
      if (res.data.code == 200) {
        this.allType = res.data.data;
      } else {
        this.allType = [{
          name: '暂无',
          value: 0
        }];
      }
      console.log(this.allType, 'allType');
    })

    if (this.role == '处理厂司机') {
      // this.chartsCar(this.driver.type)
      taskList({ workOrderDetailState: '' }).then(res => {
        console.log(res.data, '列表');
        if (res.data.code == 200) {
          let arr = res.data.data.filter((item) => item.workOrderState != 2);
          this.runningCar = res.data.data.filter((item) => item.workOrderState == 4).length;
          if (arr.length >= 1) {
            uni.setStorageSync('licenseNumber', [arr[0].licenseNumber]);
          }
          console.log(arr, 'arr');
        }
      })
      // 接受工单
      workNum({}).then(res => {
        console.log(res.data, '接受工单');
        if (res.data.code == 200) {
          this.worknums = res.data.data.orderTotal;
          this.driversewage = res.data.data.sewageTotal || 0;
          this.driverdung = res.data.data.cowDungTotal || 0;
        }
      });
      ordNum({}).then(res => {
        console.log(res.data, '待接工单');
        if (res.data.code == 200) {
          this.dNum = res.data.data.dNum || 0;
          this.dayNum = res.data.data.todayTotalOrder || 0;
          this.receiveOrder = res.data.data.receiveOrder || 0;
          console.log(this.receiveOrder, 'receiveOrder');
          if (this.receiveOrder > 0) {
            // this.flag = false;
          }
        }
      })

    } else if (this.role == '调度员') {
      this.chartsDiapatch(this.dispatch);
      dispatchOrganic().then(res => {
        console.log(res.data, '调度员有机质');
        if (res.data.code == 200) {
          this.array = res.data.data;
        }
      })
    } else if (this.role == '养殖场账号') {
      organicType().then(res => {
        console.log(res.data, '有机质类型');
        if (res.data.code == 200) {
          this.array = res.data.data;
        }
      })
      // 养殖场首页
      farmIndex().then(res => {
        console.log(res.data, '养殖场首页');
        if (res.data.code == 200) {
          this.predicOrganicWeightVOList = res.data.data.predicOrganicWeightVOList;
          this.todayOrganicWeightVOList = res.data.data.todayOrganicWeightVOList;
          this.totalOrganicWeightVOList = res.data.data.totalOrganicWeightVOList;
          this.yj.text1 = this.predicOrganicWeightVOList[0].organicType;
          this.yj.weight1 = this.predicOrganicWeightVOList[0].organicWeight;
          this.yj.text2 = this.predicOrganicWeightVOList[1].organicType;
          this.yj.weight2 = this.predicOrganicWeightVOList[1].organicWeight;
        }
      })
      //缴费
      // farmMonery({}).then(res => {
      //   console.log(res.data, '费用');
      //   this.money.a = res.data.data.newMoney;
      //   this.money.b = res.data.data.oldMoney;
      // })
      needMonney({}).then(res => {
        console.log(res.data, '待缴费');
        this.isPay = res.data.data.isPay;
        this.noPay = res.data.data.noPay;
      })
      // 有机质类型

      // 养殖场账号
      this.chartsFarm();
    } else if (this.role == '实验员' || this.role == '任务发布实验员' || this.role == '任务分配实验员') {
      lastTime().then(res => {
        console.log(res, '最新反馈时间');
        this.lastFeedbackTime = res.data.data.lastFeedbackTime;
      });
      experTotal().then(res => {
        console.log(res.data, '总累计');
        this.expert[0].value = res.data.data.completed;
        this.expert[1].value = res.data.data.unCompleted;
      })
      experCurrent().then(res => {
        console.log(res, '待开始');
        this.test.unstarted = res.data.data.unstarted;
        this.test.completed = res.data.data.completed;
      })
      experCategory().then(res => {
        console.log(res, '实验类型列表');
      })
    }
    // 已加入
    days({}).then(res => {
      console.log(res.data, '已加入');
      if (res.data.code == 200) {
        this.alDay = res.data.data || 0
      }
    })
    // 收集
    collect({}).then(res => {
      console.log(res.data, '已收集');
      if (res.data.code == 200) {
        this.sewage = res.data.data.sewage || 0;
        this.dung = res.data.data.dung || 0;
      }
    })
    // 预计待收集
    estimated({}).then(res => {
      console.log(res.data, '预计待收集');
      if (res.data.code == 200) {
        this.predictSewage = res.data.data.sewage || 0;
        this.predictDung = res.data.data.dung || 0;
      }
    })
    // 收运车辆统计
    stats({}).then(res => {
      console.log(res.data, '收运车辆统计');
      if (res.data.code == 200) {
        this.leisure = res.data.data.leisure || 0;
        this.running = res.data.data.running || 0;
        this.fault = res.data.data.fault || 0;
      }
    })
    // 待接单
    task({}).then(res => {
      console.log(res.data, '任务');
      if (res.data.code == 200) {
        this.aleardy = res.data.data.completed || 0;
        this.pending = res.data.data.uncompleted || 0;
      }
    })
    var pages = getCurrentPages();
    let currentPageRoute = pages[pages.length - 1].route;
    this.currentPage = currentPageRoute;
  }
}
</script>
<style lang="scss" scoped>
.order_box {
  // background-color: #dffcec;
  // display: flex;
  // justify-content: space-between;
  // align-items: center;
  // padding: 40rpx;
  // border-radius: 40rpx;
  // .point_sb {
  //   font-size: 38rpx;
  //   font-weight: 700;
  //   margin-bottom: 10rpx;
  // }
}

.gd_img_num {
  width: 320rpx;
  height: 300rpx;
  background-color: #fff;
  border-radius: 40rpx;
  padding: 40rpx;
  box-sizing: border-box;
}

.col_li {
  width: 320rpx;
  height: 140rpx;
  background-color: #fff;
  border-radius: 40rpx;
  padding: 35rpx;
  box-sizing: border-box;
  display: flex;

  .clo_li_num {
    font-size: 32rpx;
    color: #000;
    font-weight: 700;
    margin-bottom: 10rpx;
  }
}

.grid_box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  width: 100%;
  margin-top: 30rpx;
}

.card_box {
  box-sizing: border-box;
  position: relative;
  width: 100%;
  margin-top: 30rpx;
  background-color: #fff;
  // display: flex;
  // justify-content: space-between;
  // height: 400rpx;
  // align-items: center;
  // padding: 10rpx 40rpx 10rpx 40rpx;
  border-radius: 60rpx 60rpx 0 0;
}

.card_search_box {
  height: 100rpx;
  padding: 0 40rpx;
  border-radius: 0 0 60rpx 60rpx;
  background-color: #fedecc;
  color: #f3744d;
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.li_box {
  margin-top: 20rpx;
  border-radius: 40rpx;
  padding: 30rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #fee9e1;
  height: 100rpx;

  .li_box_point {
    width: 30rpx;
    height: 30rpx;
    border-radius: 40rpx;
    background-color: #f3744d;
    margin-right: 20rpx;
  }
}
.system_li_box {
  margin-top: 20rpx;
  border-radius: 40rpx;
  padding: 30rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #e1fef9;
  height: 100rpx;

  .li_box_point {
    width: 30rpx;
    height: 30rpx;
    border-radius: 40rpx;
    background-color: #54c68d;
    margin-right: 20rpx;
  }
}
</style>
